/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package GUIs;

import Configs.Config;
import Controllers.BieuThucChinhQuy;
import Controllers.DateNTime;
import Controllers.NguoiThueController;
import Controllers.NhanVienController_2;
import Controllers.TaiKhoanController_2;
import com.db4o.ObjectSet;
import com.sun.corba.se.impl.protocol.giopmsgheaders.FragmentMessage_1_2;
import java.util.Set;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import models.GioiTinh;
import models.NhanVien;
import models.TaiKhoan;

/**
 *
 * @author Dinh Nhan
 */
public final class f_nhanvien_sua extends javax.swing.JFrame {

    private NhanVien nv;
    private Config conn;
    private NhanVienController_2 nvc;
    private TaiKhoanController_2 tkc;
    private static f_nhanvien_sua _instance;
    private f_quanly f_ql;
    private BieuThucChinhQuy btcq;
    public f_nhanvien_sua() {
        initComponents();
    }
    
    public NhanVien getNV(){
        return this.nv;
    }
    public f_nhanvien_sua(NhanVien nv, Config conn, f_quanly f_ql) {
        this.nv = nv;
        this.conn = conn;
        this.nvc = new NhanVienController_2(this.conn);
        this.tkc = new TaiKhoanController_2(this.conn);
        this.f_ql = f_ql;
        initComponents();
        tfcmnd.setText(this.getNV().getCMND());
        tfhoten.setText(this.getNV().getHoten());
        tfmsnv.setText(this.getNV().getMSNV());
        tfsdt.setText(this.getNV().getSdt());
        Set<TaiKhoan> tks =  this.getNV().getNguoidung();
        if(!tks.isEmpty()){
            this.tkc.showAll_taikhoan_cuanhanvien(tbstk, tks);
        }
        if(this.getNV().getIsDel())
            this.rbtnXoa.doClick();
        else
            this.rbtnCon.doClick();
        if(this.getNV().getGioitinh().toString().equals("Nam")){
            this.rbtnnam.doClick();
        }
        else 
            this.rbtnnu.doClick();
        this.dpngaysinh.setDate(this.getNV().getNgaysinh());
    }
    
     public static f_nhanvien_sua getInstance(NhanVien nv, Config conn,f_quanly f_ql) {
        if (_instance == null) {
            _instance = new f_nhanvien_sua(nv,conn,f_ql);
        }
        // Lam moi lai noi dung
        else{
            
            _instance.conn = conn;
            _instance.nvc = new NhanVienController_2(conn);
            _instance.nv = nv;
        }
       
        return _instance;
    }

    private void formWindowOpened(java.awt.event.WindowEvent evt) {                                  
        tfcmnd.setText(this.getNV().getCMND());
        tfhoten.setText(this.getNV().getHoten());
        tfmsnv.setText(this.getNV().getMSNV());
        tfsdt.setText(this.getNV().getSdt());
        if(this.getNV().getIsDel()==true)
            this.rbtnXoa.doClick();
        else
            this.rbtnCon.doClick();
        if(this.getNV().getGioitinh().toString().equals("Nam")){
            this.rbtnnam.isSelected();
        }
        else this.rbtnnu.isSelected();
        this.dpngaysinh.setDate(this.getNV().getNgaysinh());
        
    }                                 
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        popupmenu = new javax.swing.JPopupMenu();
        itemsua = new javax.swing.JMenuItem();
        itemxoa = new javax.swing.JMenuItem();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        tfmsnv = new javax.swing.JTextField();
        tfhoten = new javax.swing.JTextField();
        tfcmnd = new javax.swing.JTextField();
        dpngaysinh = new org.jdesktop.swingx.JXDatePicker();
        rbtnnam = new javax.swing.JRadioButton();
        rbtnnu = new javax.swing.JRadioButton();
        tfsdt = new javax.swing.JTextField();
        btnsua = new javax.swing.JButton();
        btnlammoi = new javax.swing.JButton();
        btnthoat = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        rbtnCon = new javax.swing.JRadioButton();
        rbtnXoa = new javax.swing.JRadioButton();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbstk = new javax.swing.JTable();
        jLabel13 = new javax.swing.JLabel();

        itemsua.setText("Sửa thông tin tài khoản");
        itemsua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemsuaActionPerformed(evt);
            }
        });
        popupmenu.add(itemsua);

        itemxoa.setText("Xóa tài khoản");
        itemxoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemxoaActionPerformed(evt);
            }
        });
        popupmenu.add(itemxoa);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Sửa thông tin nhân viên");
        setResizable(false);

        jLabel1.setText("MSNV :");

        jLabel2.setText("Họ Tên :");

        jLabel3.setText("Ngày Sinh :");

        jLabel4.setText("Giới Tính :");

        jLabel5.setText("Số CMND :");

        jLabel6.setText("Số Điện Thoại :");

        tfmsnv.setEditable(false);

        tfhoten.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfhotenKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tfhotenKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tfhotenKeyTyped(evt);
            }
        });

        dpngaysinh.setDate(new java.util.Date(714718800000L));

        buttonGroup1.add(rbtnnam);
        rbtnnam.setSelected(true);
        rbtnnam.setText("Nam");
        rbtnnam.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                rbtnnamMouseClicked(evt);
            }
        });

        buttonGroup1.add(rbtnnu);
        rbtnnu.setText("Nữ");
        rbtnnu.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                rbtnnuMouseClicked(evt);
            }
        });

        btnsua.setText("Sửa");
        btnsua.setEnabled(false);
        btnsua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnsuaActionPerformed(evt);
            }
        });

        btnlammoi.setText("Làm Mới");
        btnlammoi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnlammoiActionPerformed(evt);
            }
        });

        btnthoat.setText("Thoát");
        btnthoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnthoatActionPerformed(evt);
            }
        });

        jLabel8.setText("Trạng Thái :");

        buttonGroup2.add(rbtnCon);
        rbtnCon.setText("Đang Sử Dụng");
        rbtnCon.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                rbtnConMouseClicked(evt);
            }
        });

        buttonGroup2.add(rbtnXoa);
        rbtnXoa.setSelected(true);
        rbtnXoa.setText("Đã Xóa");
        rbtnXoa.setEnabled(false);

        jLabel9.setText("Tài Khoản : ");

        jLabel10.setText("*");

        jLabel11.setText("*");

        jLabel12.setText("*");

        tbstk.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Tên Tài Khoản"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        tbstk.setComponentPopupMenu(popupmenu);
        jScrollPane1.setViewportView(tbstk);

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel13.setText("SỬA THÔNG TIN NHÂN VIÊN");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(76, 76, 76)
                        .addComponent(btnsua, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnlammoi)
                        .addGap(18, 18, 18)
                        .addComponent(btnthoat)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel13)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(13, 13, 13)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(tfsdt, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addComponent(rbtnCon)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(rbtnXoa))
                                            .addComponent(dpngaysinh, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(tfmsnv)
                                            .addComponent(tfhoten)
                                            .addComponent(tfcmnd, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addComponent(rbtnnam)
                                                .addGap(18, 18, 18)
                                                .addComponent(rbtnnu)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel10)
                                            .addComponent(jLabel11)))
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addContainerGap(25, Short.MAX_VALUE))))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(108, 108, 108)
                            .addComponent(jLabel7))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel8))))
                    .addContainerGap(220, Short.MAX_VALUE)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel13)
                .addGap(7, 7, 7)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfmsnv, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfhoten, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(18, 18, 18))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tfcmnd, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11))
                        .addGap(8, 8, 8)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(dpngaysinh, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rbtnCon)
                    .addComponent(rbtnXoa))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rbtnnam)
                    .addComponent(rbtnnu))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfsdt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jLabel9))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(32, 32, 32)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnsua)
                    .addComponent(btnlammoi)
                    .addComponent(btnthoat))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(154, 154, 154)
                    .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jLabel6)
                    .addGap(0, 198, Short.MAX_VALUE)
                    .addComponent(jLabel7)
                    .addContainerGap()))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(19, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void btnlammoiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnlammoiActionPerformed
        tfcmnd.setText("");
        tfhoten.setText("");
        tfsdt.setText("");
    }//GEN-LAST:event_btnlammoiActionPerformed

    private void btnsuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnsuaActionPerformed
        this.btcq = new BieuThucChinhQuy(tfhoten.getText(), "[^!@#$%^&*\\{\\}\\\\'\\\"]+$");
        if(!this.btcq.isBoolean()){
            JOptionPane.showMessageDialog(this, "Họ tên không hợp lệ.", "Thông báo", JOptionPane.ERROR_MESSAGE);
            this.tfhoten.requestFocus(); 
        }
        else if (!DateNTime.checkTuoi(dpngaysinh.getDate())) {
            JOptionPane.showMessageDialog(this, "Ngày tháng năm sinh không hợp lệ.", "Thông báo", JOptionPane.ERROR_MESSAGE);
            this.dpngaysinh.requestFocus();
        }
        else{
            this.btcq.setBtchinhquy("^[0-9]{9,15}$");
            this.btcq.setChuoikt(this.tfsdt.getText());
            if (!this.btcq.isBoolean()) {
                JOptionPane.showMessageDialog(this, "Số điện thoại không hợp lệ.", "Thông báo", JOptionPane.ERROR_MESSAGE);
                this.tfsdt.requestFocus();
            }
            else{
                if(!"".equals(tfhoten.getText()) && !"".equals(tfcmnd.getText()) && !"".equals(tfsdt.getText())){
                    GioiTinh gioitinh;
                    if(rbtnnam.isSelected()){
                        gioitinh = GioiTinh.Nam;
                    }
                    else gioitinh = GioiTinh.Nữ;
                    NhanVien nv2 = new NhanVien(tfcmnd.getText(), tfhoten.getText(), gioitinh, tfsdt.getText(), dpngaysinh.getDate());
                    nv2.setMSNV(tfmsnv.getText());
                    if(rbtnCon.isSelected())
                        nv2.setIsDel(false);
                    else
                        nv2.setIsDel(true);
                    this.nvc.editNhanVien(nv2);
                    this.f_ql.getMyFormat().clearTable(this.f_ql.getTbnv());
                    this.f_ql.gettkcontrol().showAllNhanVien(this.f_ql.getTbnv());
                    int check = JOptionPane.showConfirmDialog(this, "sửa tài khoản thành công bạn có muốn tiếp tục sửa", "Warning", JOptionPane.YES_NO_OPTION);
                    if(check==JOptionPane.NO_OPTION)
                        this.dispose();
                    
                    }
                    else
                        JOptionPane.showMessageDialog(this, "Thông tin * phải có");
            }
        }
       
    }//GEN-LAST:event_btnsuaActionPerformed

    private void tfhotenKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfhotenKeyTyped
       
    }//GEN-LAST:event_tfhotenKeyTyped

    private void tfhotenKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfhotenKeyPressed
        btnsua.setEnabled(true);
    }//GEN-LAST:event_tfhotenKeyPressed

    private void tfhotenKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfhotenKeyReleased
        //btnsua.setVisible(true);
    }//GEN-LAST:event_tfhotenKeyReleased

    private void btnthoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnthoatActionPerformed
       
        this.dispose();
    }//GEN-LAST:event_btnthoatActionPerformed

    private void rbtnConMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rbtnConMouseClicked
        btnsua.setEnabled(true);
    }//GEN-LAST:event_rbtnConMouseClicked

    private void rbtnnuMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rbtnnuMouseClicked
        btnsua.setEnabled(true);
    }//GEN-LAST:event_rbtnnuMouseClicked

    private void rbtnnamMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rbtnnamMouseClicked
       btnsua.setEnabled(true);
    }//GEN-LAST:event_rbtnnamMouseClicked

    private void itemsuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemsuaActionPerformed
        int row = tbstk.getSelectedRow();
        if (row != -1) {
            String user = tbstk.getValueAt(row, 0).toString();
            TaiKhoan tk = this.tkc.getWithTenTaiKhoan(user);
            //f_nhanvien_sua f = f_nhanvien_sua.getInstance(nv, this.conn);
            f_taikhoan_sua f_tk_s  = new f_taikhoan_sua(conn,tk);
            f_tk_s.setVisible(true);
        }
        tbstk.clearSelection();
    }//GEN-LAST:event_itemsuaActionPerformed

    private void itemxoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemxoaActionPerformed
        int check = JOptionPane.showConfirmDialog(this, "Bạn có muốn xóa tài khoản này", "Warning", JOptionPane.YES_NO_OPTION);
        if(check == 0){
            int row = tbstk.getSelectedRow();
            if (row != -1) {
                String user = tbstk.getValueAt(row, 1).toString();
                TaiKhoan tk = this.tkc.getWithTenTaiKhoan(user);
                //f_nhanvien_sua f = f_nhanvien_sua.getInstance(nv, this.conn);
                this.tkc.deleteTaiKhoan(tk, tk.getMSNV());
                JOptionPane.showMessageDialog(this, "Đã xóa Nhân Viên Thành Công!");
            }
            tbstk.clearSelection();
        }
    }//GEN-LAST:event_itemxoaActionPerformed

    /**
     * @param args the command line arguments
     */
  

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnlammoi;
    private javax.swing.JButton btnsua;
    private javax.swing.JButton btnthoat;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    public org.jdesktop.swingx.JXDatePicker dpngaysinh;
    private javax.swing.JMenuItem itemsua;
    private javax.swing.JMenuItem itemxoa;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPopupMenu popupmenu;
    private javax.swing.JRadioButton rbtnCon;
    private javax.swing.JRadioButton rbtnXoa;
    private javax.swing.JRadioButton rbtnnam;
    private javax.swing.JRadioButton rbtnnu;
    private javax.swing.JTable tbstk;
    private javax.swing.JTextField tfcmnd;
    private javax.swing.JTextField tfhoten;
    private javax.swing.JTextField tfmsnv;
    private javax.swing.JTextField tfsdt;
    // End of variables declaration//GEN-END:variables
}
